home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
minix
/
up1510b.tgz
/
up1510b
/
src
/
commands
/
kermit
/
ckufio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-23
|
29KB
|
1,098 lines
char *ckzv = "Unix file support, 4E(037) 27 Jan 88";
/* C K U F I O -- Kermit file system support for Unix systems */
/* 4E, conditionals added for Apollo Aegis. */
/*
Author: Frank da Cruz (SY.FDC@CU20B),
Columbia University Center for Computing Activities, January 1985.
Copyright (C) 1985, Trustees of Columbia University in the City of New York.
Permission is granted to any individual or institution to use, copy, or
redistribute this software so long as it is not sold for profit, provided this
copyright notice is retained.
*/
/* Includes */
#include <sys/types.h> /* Data types */
#include "ckcker.h" /* Kermit definitions */
#include "ckcdeb.h" /* Typedefs, debug formats, etc */
#include <ctype.h> /* Character types */
#include <stdio.h> /* Standard i/o */
#ifdef MINIX
#include <limits.h>
#endif
#include <sys/dir.h> /* Directory structure */
#include <pwd.h> /* Password file for shell name */
#ifdef CIE
#include <stat.h> /* File status */
#else
#include <sys/stat.h>
#endif
/* Berkeley Unix Version 4.x */
/* 4.1bsd support added by Charles E Brooks, EDN-VAX */
#ifdef BSD4
#ifdef MAXNAMLEN
#define BSD42
char *ckzsys = " 4.2 BSD";
#else
#ifdef FT18
#define BSD41
char *ckzsys = " Fortune For:Pro 1.8";
#else
#define BSD41
char *ckzsys = " 4.1 BSD";
#endif
#endif
#endif
/* 2.9bsd support contributed by Bradley Smith, UCLA */
#ifdef BSD29
char *ckzsys = " 2.9 BSD";
#endif
/* Version 7 Unix */
#ifdef V7
char *ckzsys = " Version 7 Unix";
#endif
/* DEC Professional-300 series with Venturcom Venix v1 */
#ifdef PROVX1
char *ckzsys = " DEC Pro-3xx/Venix v1";
#endif
/* NCR Tower support contributed by John Bray, Auburn, AL. */
/* Tower OS is like Sys III but with BSD features -- mostly follows BSD. */
#ifdef TOWER1
char *ckzsys = " NCR Tower 1632, OS 1.02";
#endif
/* Sys III/V, Xenix, PC/IX,... support by Herm Fischer, Litton Data Systems */
#ifdef UXIII
#ifdef XENIX
char *ckzsys = " Xenix/286";
#else
#ifdef PCIX
char *ckzsys = " PC/IX";
#else
#ifdef ISIII
char *ckzsys = " Interactive Systems Corp, System III";
#else
#ifdef ZILOG
char *ckzsys = " Zilog S8000 Zeus 3.21+";
#else
char *ckzsys = " AT&T System III/System V";
#endif
#endif
#endif
#endif
#endif
/* Definitions of some Unix system commands */
char *DELCMD = "rm -f "; /* For file deletion */
char *PWDCMD = "pwd "; /* For saying where I am */
#ifdef FT18
char *DIRCMD = "ls -l | more "; /* For directory listing */
char *TYPCMD = "more "; /* For typing a file */
#else
char *TYPCMD = "cat "; /* For typing a file */
char *DIRCMD = "ls -l "; /* For directory listing */
#endif
#ifdef FT18
#undef BSD4
#endif
#ifdef BSD4
char *SPACMD = "pwd ; quota ; df ."; /* Space/quota of current directory */
#else
#ifdef FT18
char #SPACMD = "pwd ; du ; df .";
#else
char *SPACMD = "df ";
#endif
#endif
char *SPACM2 = "df "; /* For space in specified directory */
#ifdef FT18
#define BSD4
#endif
#ifdef BSD4
char *WHOCMD = "finger "; /* For seeing who's logged in */
#else
char *WHOCMD = "who "; /* For seeing who's logged in */
#endif
/*
Functions (n is one of the predefined file numbers from ckermi.h):
zopeni(n,name) -- Opens an existing file for input.
zopeno(n,name) -- Opens a new file for output.
zclose(n) -- Closes a file.
zchin(n,&c) -- Gets the next character from an input file.
zsout(n,s) -- Write a null-terminated string to output file, buffered.
zsoutl(n,s) -- Like zsout, but appends a line terminator.
zsoutx(n,s,x) -- Write x characters to output file, unbuffered.
zchout(n,c) -- Add a character to an output file, unbuffered.
zchki(name) -- Check if named file exists and is readable, return size.
zchko(name) -- Check if named file can be created.
znewn(name,s) -- Make a new unique file name based on the given name.
zdelet(name) -- Delete the named file.
zxpand(string) -- Expands the given wildcard string into a list of files.
znext(string) -- Returns the next file from the list in "string".
zxcmd(cmd) -- Execute the command in a lower fork.
zclosf() -- Close input file associated with zxcmd()'s lower fork.
zrtol(n1,n2) -- Convert remote filename into local form.
zltor(n1,n2) -- Convert local filename into remote form.
zchdir(dirnam) -- Change working directory.
zhome() -- Return pointer to home directory name string.
zkself() -- Kill self, log out own job.
*/
#ifdef FT18
#define PROVX1
#endif
/* Which systems include <sys/file.h>... */
#ifndef PROVX1
#ifndef aegis
#ifndef CIE
#ifndef MINIX
#ifndef XENIX
/* Watch out, some versions of Xenix might need to do this include, */
/* but reportedly SCO Xenix 2.2 on an 80x86 system does not. */
#include <sys/file.h> /* File access */
#endif
#endif
#endif
#endif
#endif
#ifdef FT18
#undef PROVX1
#endif
/* Some systems define these symbols in include files, others don't... */
#ifndef R_OK
#define R_OK 4 /* For access */
#endif
#ifndef W_OK
#define W_OK 2
#endif
#ifdef PROVX1
#define MAXNAMLEN DIRSIZ /* Max file name length */
#endif
#ifdef UXIII
#include <fcntl.h>
#define MAXNAMLEN DIRSIZ
#endif
#ifndef O_RDONLY
#define O_RDONLY 000
#endif
#ifndef MAXNAMLEN
#define MAXNAMLEN 14 /* If still not defined... */
#endif
#ifdef PROVX1
#define MAXWLD 50 /* Maximum wildcard filenames */
#else
#ifdef BSD29
#define MAXWLD 50 /* Maximum wildcard filenames */
#else
#define MAXWLD 500
#endif
#endif
/* Declarations */
FILE *fp[ZNFILS] = { /* File pointers */
NULL, NULL, NULL, NULL, NULL, NULL, NULL };
static int pid; /* pid of child fork */
static int fcount; /* Number of files in wild group */
static char nambuf[MAXNAMLEN+2]; /* Buffer for a filename */
char *malloc(), *getenv(), *strcpy(); /* System functions */
extern errno; /* System error code */
static char *mtchs[MAXWLD], /* Matches found for filename */
**mtchptr; /* Pointer to current match */
/* Z K S E L F -- Kill Self: log out own job, if possible. */
/* Note, should get current pid, but if your system doesn't have */
/* getppid(), then just kill(0,9)... */
zkself() { /* For "bye", but no guarantee! */
#ifdef PROVX1
return(kill(0,9));
#else
#ifdef V7
return(kill(0,9));
#else
#ifdef TOWER1
return(kill(0,9));
#else
#ifdef FT18
return(kill(0,9));
#else
#ifdef aegis
return(kill(0,9));
#else
return(kill(getppid(),1));
#endif
#endif
#endif
#endif
#endif
}
/* Z O P E N I -- Open an existing file for input. */
zopeni(n,name) int n; char *name; {
debug(F111," zopeni",name,n);
debug(F101," fp","",(int) fp[n]);
if (chkfn(n) != 0) return(0);
if (n == ZSYSFN) { /* Input from a system function? */
debug(F110," invoking zxcmd",name,0);
return(zxcmd(name)); /* Try to fork the command */
}
if (n == ZSTDIO) { /* Standard input? */
if (isatty(0)) {
ermsg("Terminal input not allowed");
debug(F110,"zopeni: attempts input from unredirected stdin","",0);
return(0);
}
fp[ZIFILE] = stdin;
return(1);
}
fp[n] = fopen(name,"r"); /* Real file. */
debug(F111," zopeni", name, (int) fp[n]);
if (fp[n] == NULL) perror("zopeni");
return((fp[n] != NULL) ? 1 : 0);
}
/* Z O P E N O -- Open a new file for output. */
zopeno(n,name) int n; char *name; {
debug(F111," zopeno",name,n);
if (chkfn(n) != 0) return(0);
if ((n == ZCTERM) || (n == ZSTDIO)) { /* Terminal or standard output */
fp[ZOFILE] = stdout;
debug(F101," fp[]=stdout", "", (int) fp[n]);
return(1);
}
fp[n] = fopen(name,"w"); /* A real file, try to open */
if (fp[n] == NULL) {
perror("zopeno can't open");
} else {
chown(name, getuid(), getgid()); /* In case set[gu]id */
if (n == ZDFILE) setbuf(fp[n],(char *)NULL); /* Debugging file unbuffered */
}
debug(F101, " fp[n]", "", (int) fp[n]);
return((fp[n] != NULL) ? 1 : 0);
}
/* Z C L O S E -- Close the given file. */
/* Returns 0 if arg out of range, 1 if successful, -1 if close failed. */
zclose(n) int n; {
int x;
if (chkfn(n) < 1) return(0); /* Check range of n */
if ((